package com.mintyfresh.tns.client;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.util.*;
import com.mintyfresh.tns.util.*;


public class HighScoresWindow extends JComponent {
	/**
	 * These are the layers of the graphics object, in the order they are drawn onscreen 
	 * */
	private final String playerTitle = "Player";
	private final String scoreTitle = "Score";
	private ArrayList<String> playerNames;
	private ArrayList<String> scores;
	
	public HighScoresWindow(RoundResultInfo info) {
		playerNames = new ArrayList<String>();
		scores = new ArrayList<String>();
		LinkedList<Player> highScores = info.getHighScores();
		for(Player p : highScores) {
			playerNames.add(p.getUsername());
			scores.add(new Double(Math.round(p.getScore())).toString());
		}
	}

	/**
	 * Paint overrides JComponent's default paint
	 * Here we paint all the layers that make up the screen onto a 2D graphics object
	 * @author James
	 */
	public void paint(Graphics g) {
		Graphics2D g2d = (Graphics2D)g;
		g2d.drawLine(150, 0, 150, 80+playerNames.size()*20);
		g2d.drawString(playerTitle, 20, 20);
		g2d.drawString(scoreTitle, 170, 20);
		for(int i = 0; i < playerNames.size(); i++) {
			g2d.drawString(playerNames.get(i), 20, (60+(i*20)));
			g2d.drawString((String)scores.get(i), 170, (60+(i*20)));
		}
	}
}
